<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    
    <title>充值卡管理</title>
    <link href="${ctx}/style/style.css" rel="stylesheet" type="text/css" />
    <script language="JavaScript" src="${ctx}/scripts/jquery.js"></script>
	<script type="text/javascript" src="${ctx}/scripts/lhgdialog/lhgdialog.js" ></script>		
	<script type="text/javascript" src="${ctx}/scripts/dateTime/WdatePicker.js" ></script>			
	<script type="text/javascript">
		var pop;
		function add(){
			pop = $.dialog({ 
				lock: true, 
				width: '400px',
  				height: '150px',
  				max: false,
   				min: false,
  				title:  "新增充值卡",
			    content: 'url:Prepaidcard_toAdd.action',
			    ok : addCard,
			    cancel: true
			});
		}
		function addCard(){
			 var cardnumber =  pop.content.document.getElementById('cardnumber').value ;
			 var cardmoney =  pop.content.document.getElementById('cardmoney').value ;
			 if(cardnumber != '' && cardmoney != '' && !isNaN(cardnumber) && !isNaN(cardmoney)){
				 $.ajax({
					url: "Prepaidcard_add.action?prepaidcard.cardnumber="+cardnumber+"&prepaidcard.cardmoney="+cardmoney,
					type : 'post',
					dataType : 'json',
					beforeSend:loading,
					dataFilter :function (data, textStatus) {
						$("#loading").hide();
			         	window.location.reload();
			        } 
				});
			}else{
				return false;
			}	
		}
		function loading(){
			$("#loading").show();
		}
		function sel(){
			document.forms.fom1.submit();
		}
		function pwdSel(id){
			$("#cardNum_desp").html($("#card_"+id).val());
			$("#cardPwd_desp").html($("#pwd_"+id).val());
			
			$.dialog({ 
				lock: true, 
				width: '400px',
  				height: '100px',
  				max: false,
   				min: false,
  				title:  "充值卡信息",
			    content: $("#card_view").html(),
			    cancel: true
			});
			
		}
		function cardCopy(type){
			var txt = '';
			if(type == '0'){
				txt = $("#cardNum_desp").html();
			}else if(type == '1'){
				txt = $("#cardPwd_desp").html();
			}
			if (window.clipboardData) {
	                window.clipboardData.clearData();
	                window.clipboardData.setData("Text", txt);
	        } else if (navigator.userAgent.indexOf("Opera") != -1) {
	                window.location = txt;
	        } else if (window.netscape) {
	                try {
	                        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
	                } catch (e) {
	                        alert("您的firefox安全限制限制您进行剪贴板操作，请在新窗口的地址栏里输入'about:config'然后找到'signed.applets.codebase_principal_support'设置为true'");
	                        return false;
	                }
	                var clip = Components.classes["@mozilla.org/widget/clipboard;1"].createInstance(Components.interfaces.nsIClipboard);
	                if (!clip)
	                        return;
	                var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
	                if (!trans)
	                        return;
	                trans.addDataFlavor('text/unicode');
	                var str = new Object();
	                var len = new Object();
	                var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
	                var copytext = txt;
	                str.data = copytext;
	                trans.setTransferData("text/unicode", str, copytext.length * 2);
	                var clipid = Components.interfaces.nsIClipboard;
	                if (!clip)
	                        return false;
	                clip.setData(trans, null, clipid.kGlobalClipboard);
	       	 }
		}
	</script>
 </head>
 <body>
  	<div class="place" >
	    <span>位置：</span>
	    <ul class="placeul">
	    	<li><a href="#">充值卡管理</a></li>
	    </ul>
    </div>
    
    
	<div class="formtitle"><span>操作</span></div>
    <div class="tools">
    	<form id="fom1" action="Prepaidcard_list.action" method="post">
		   <table class="dataTable" style="margin-left: 20px;" width="98%">
		   		<tr>
		   			<th align="right" width="50">状态:</th>
		   			<td width="200">
		   				<s:select name="prepaidcard.cardstatus" cssStyle="width:130px;"
							list="#{'0':'未使用','1':'已使用'}" listKey="key" listValue="value"
							headerKey="" headerValue="---------请选择------" cssClass="input" />
		   			</td>
		   			
		   			<th align="right" width="50">使用人:</th>
		   			<td width="200">
						<s:select name="prepaidcard.useuser" list="agentaccountinfoList" listKey="username" listValue="truename"
							headerKey="" headerValue="-------请选择-------" cssClass="input" />
					</td>
		   			<td width="100" rowspan="2">
						<ul class="toolbar1"  >
				        	<li onclick="sel()"><span><img src="${ctx}/images/search.png" /></span>查询</li>
				        </ul>
					</td>
		   			<td align="right" rowspan="2">
				        <ul class="toolbar1"  >
				        	<li onclick="add()"><span><img src="${ctx}/images/t01.png" /></span>新增</li>
				        </ul>
		   			</td>
		   		</tr>
		   		<tr>
		   			<th align="right" width="70">使用时间:</th>
		   			<td colspan="3">
		   				<s:textfield cssClass="input" name="prepaidcard.start_time" cssStyle="width:130px;"
							onclick="WdatePicker({startDate:'%y-%M-01 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})" />
						~
						<s:textfield cssClass="input" name="prepaidcard.end_time" cssStyle="width:130px;"
							onclick="WdatePicker({startDate:'%y-%M-%d 23:59:59',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})" />
		   			</td>
		   		</tr>
		   </table>
		 </form>
    </div>
	<div class="formtitle" ><span>统计</span></div>
    <table class="dataTable" width="98%" style="margin-left: 20px;margin-bottom:5px;">
   		<tr >
   			<th width="70" height="25" align="right">数量:</th>
   			<td width="200">
   				<s:property value="prepaidcard.card_num"/>
   			</td>
   			<th align="right" width="55">金额(元):</th>
   			<td>
   				<s:property value="prepaidcard.card_money"/>
   			</td>
   		</tr>
   </table>
    	
    <table class="imgtable" >
	    <thead>
		    <tr>
			    <th width="40px;">序号</th>
			    <th>卡号</th>
			    <th>密码</th>
			    <th>金额</th>
			    <th>生成时间</th>
			    <th>状态</th>
			    <th>使用人</th>
			    <th>使用时间</th>
		    </tr>
	    </thead>
	    <tbody>
	    	<s:if test="prepaidcardList==null || prepaidcardList.isEmpty()">
				<tr class="toolbar">
					<td colspan="10" align="left" height="25px">
						<font color="red">提示：未查询到数据!</font>
					</td>
				</tr>
			</s:if>
			<s:else>
				<s:iterator id="p" value="prepaidcardList" status="loop">
					<tr>
					    <td><s:property  value="#p.id" /></td>
					    <td style="width: 80px">
					    	<s:property  value="#p.cardnumber" />
					    	<input type="hidden" id="card_<s:property  value="#loop.index" />"  value="<s:property  value="#p.cardnumber" />" />
					    	<input type="hidden" id="pwd_<s:property  value="#loop.index" />"  value="<s:property  value="#p.cardpwd" />" />
					    </td>
						<td width="60">
							<input type="button" onclick="pwdSel('<s:property  value="#loop.index" />')" value="查看" class="btn2">
						</td>
					    <td><s:property  value="#p.cardmoney" /></td>
					    <td><s:property  value="#p.createdate" /></td>
					    <td>
							<s:if test="#p.cardstatus == 0">
								<font color="blue">未使用</font>
							</s:if>
							<s:else>
								<font color="red">已使用</font>
							</s:else>
						</td>
						<td>
							<s:iterator id="a" value="agentaccountinfoList">
								<s:if test="#a.username == #p.useuser">
									<s:property  value="#a.truename" />
								</s:if>
							</s:iterator>
							&nbsp;
						</td>	
						<td><s:property  value="#p.usedate" />&nbsp;</td>
				    </tr>
				</s:iterator>
			</s:else>
	    </tbody>
    </table>
    <div class="pagin">
    	<div class="message">
			共
			<s:property value="totalCount" />
			条记录&nbsp;共
			<s:property value="totalPage" />
			页&nbsp;当前第
			<s:property value="currentPage" />
			页&nbsp;
		</div>
        <ul class="paginList">
	        <li class="paginItem">
				<pagetag:pages currentPage="${currentPage}"
					totalPage="${totalPage}" styleClass="page" theme="text">
					<input type="hidden" name="callpaymentrecord.start_time"
						value="${prepaidcard.start_time}" />
					<input type="hidden" name="callpaymentrecord.end_time"
						value="${prepaidcard.end_time}" />
					<input type="hidden" name="callpaymentrecord.useuser"
						value="${prepaidcard.useuser}" />	
					<input type="hidden" name="callpaymentrecord.cardstatus"
						value="${prepaidcard.cardstatus}" />		
				</pagetag:pages>
			</li>
        </ul>
    </div>
    
   
	<script type="text/javascript">
		$('.imgtable tbody tr:odd').addClass('odd');
	</script>
	<div id="loading" style="position:absolute; display:none; left:-1px; top:1px; width:100%; height:100%; background-color:#FFFFFF; 
			filter:alpha(opacity=50);-moz-opacity:0.5; -khtml-opacity: 0.5;opacity: 0.5; z-index:1000;"> 
		<div  style="position:absolute;left:180px;top:150px;width:100px;height:100px;background-color:#FFFFFF; z-index:9001;" >
			<img alt="" id="wait1" src="${ctx}/images/loading.gif" >
		</div>
	</div>
	
	<div id="card_view" style="display: none">
		<table class="dataTable" width="400" style="margin-left: 10px;margin-bottom:5px;">
   			<tr>
	   			<th align="right" width="80" height="35">卡号:</th>
	   			<td id="cardNum_desp">&nbsp;</td>
	   			<td><input type="button" onclick="cardCopy('0')" value="复制" class="btn2"> </td>
   			</tr>
   			<tr>
	   			<th align="right" height="35">密码:</th>
	   			<td id="cardPwd_desp">&nbsp;</td>
	   			<td><input type="button" onclick="cardCopy('1')" value="复制" class="btn2"> </td>
   			</tr>
  		 </table>
	</div>
  </body>
</html>
